﻿/*
 * Creado por SharpDevelop.
 * Usuario: seba
 * Fecha: 01/08/2009
 * Hora: 07:48 p.m.
 * 
 * Para cambiar esta plantilla use Herramientas | Opciones | Codificación | Editar Encabezados Estándar
 */
using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Collections.Generic;
using System.Text;

namespace SACP
{
	/// <summary>
	/// Description of NumericTextBox.
	/// </summary>
	/// 
	
[ToolboxItem(true)]
[ToolboxBitmap(typeof(TextBox))]	
public class NumericTextBoxSpS : TextBox
{
    bool allowSpace = false;
    bool VB = false;

    // Restricts the entry of characters to digits (including hex), the negative sign,
    // the decimal point, and editing keystrokes (backspace).
    protected override void OnKeyPress(KeyPressEventArgs e)
    {
        base.OnKeyPress(e);
     //MessageBox.Show(Convert.ToInt16(e.KeyChar).ToString());
       
       if (e.KeyChar ==8 ) {
         e.Handled = false;
         return;
       }


       bool IsDec = false;
        int nroDec = 0;

       for (int i=0 ; i<base.Text.Length; i++) {
         if ( base.Text[i] == ',' )
            IsDec = true;

        // if ( IsDec && nroDec++ >=2) {
        //    e.Handled = true;
        //    return;
        // }


       }

       if ( e.KeyChar>=48 && e.KeyChar<=57)
         e.Handled = false;
       else if (e.KeyChar==44)         
         e.Handled = (IsDec) ? true:false;
       else
         e.Handled = true;
    }

 

    public bool AllowSpace
    {
        set
        {
            this.allowSpace = value;
        }

        get
        {
            return this.allowSpace;
        }
    }
    
    [Category("Custom")]
    [Description("Set/Get dot length(0 is integer, 10 is maximum).")]
    [DefaultValue(false)]    
    public bool SetVB
    {
    	set
    	{
    		this.VB = value; 
    	}
    	get
    	{
    		return this.VB; 
    	}
    }
}


 
	
}
